package com.lc.yygh.hosp.controller.api;

import com.lc.yygh.common.result.Result;
import com.lc.yygh.hosp.service.DepartmentService;
import com.lc.yygh.hosp.service.HospitalService;
import com.lc.yygh.hosp.service.HospitalSetService;
import com.lc.yygh.hosp.service.ScheduleService;
import com.lc.yygh.model.hosp.Hospital;
import com.lc.yygh.model.hosp.Schedule;
import com.lc.yygh.vo.hosp.DepartmentVo;
import com.lc.yygh.vo.hosp.HospitalQueryVo;
import com.lc.yygh.vo.hosp.ScheduleOrderVo;
import com.lc.yygh.vo.order.SignInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags = "医院管理接口")
@RestController
@RequestMapping("/api/hosp/hospital")
public class HospitalApiController {

    @Autowired
    private HospitalService hospitalService;

    @Autowired
    private DepartmentService departmentService;

    @Autowired
    private ScheduleService scheduleService;

    @Autowired
    private HospitalSetService hospitalSetService;
    //分页查询结果
    @ApiOperation(value = "获取分页列表")
    @GetMapping("{page}/{limit}")
    public Result findHospitalList(@ApiParam(name = "page", value = "当前页码", required = true)
                                   @PathVariable Integer page,

                                   @ApiParam(name = "limit", value = "每页记录数", required = true)
                                   @PathVariable Integer limit,

                                   @ApiParam(name = "hospitalQueryVo", value = "查询对象", required = false)
                                   HospitalQueryVo hospitalQueryVo){//Get请求不能用@RequestBody
        Page<Hospital> page1 = hospitalService.selectPage(page, limit, hospitalQueryVo);
        return Result.success(page1);
    }

    @ApiOperation(value = "根据医院名称获取医院列表")
    @GetMapping("findByHosname/{hosname}")
    public Result findByHosname(
            @ApiParam(name = "hosname", value = "医院名称", required = true)
            @PathVariable String hosname) {
        List<Hospital> list = hospitalService.findByHosname(hosname);
        return Result.success(list);
    }

    @ApiOperation(value = "医院预约挂号详情")
    @GetMapping("{hoscode}")
    public Result item(
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable String hoscode) {
        return Result.success(hospitalService.item(hoscode));
    }

    @ApiOperation(value = "获取科室列表")
    @GetMapping("department/{hoscode}")
    public Result index(
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable String hoscode) {
        List<DepartmentVo> deptTree = departmentService.findDeptTree(hoscode);
        return Result.success(deptTree);
    }

    @ApiOperation(value = "获取可预约排班数据")
    @GetMapping("auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public Result getBookingSchedule(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Integer page,
            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Integer limit,
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable String hoscode,
            @ApiParam(name = "depcode", value = "科室code", required = true)
            @PathVariable String depcode) {
        Map<String, Object> bookingScheduleRule = scheduleService.getBookingScheduleRule(page, limit, hoscode, depcode);
        return Result.success(bookingScheduleRule);
    }


    @ApiOperation(value = "获取指定日期的排班数据")
    @GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public Result findScheduleList(
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable String hoscode,
            @ApiParam(name = "depcode", value = "科室code", required = true)
            @PathVariable String depcode,
            @ApiParam(name = "workDate", value = "排班日期", required = true)
            @PathVariable String workDate){
        List<Schedule> detailSchedule = scheduleService.getDetailSchedule(hoscode, depcode, workDate);
        return Result.success(detailSchedule);
    }

    @ApiOperation(value = "根据排班id获取排班数据")
    @GetMapping("getSchedule/{scheduleId}")
    public Result getSchedule( @ApiParam(name = "scheduleId",value = "排班id",required = true)
                               @PathVariable String scheduleId){
        Schedule schedule = scheduleService.getById(scheduleId);
        return Result.success(schedule);
    }

    @ApiOperation(value = "根据排班id获取预约下单数据")
    @GetMapping("inner/getScheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(
            @ApiParam(name = "scheduleId", value = "排班id", required = true)
            @PathVariable("scheduleId") String scheduleId) {
        return scheduleService.getScheduleOrderVo(scheduleId);
    }

    @ApiOperation(value = "获取医院签名信息")
    @GetMapping("inner/getSignInfoVo/{hoscode}")
    public SignInfoVo getSignInfoVo(
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable("hoscode") String hoscode) {
        return hospitalSetService.getSignInfoVo(hoscode);
    }
}
